<?php

/**
 * FileName: SystemSettingPaymentForm.php
 * Author: 790213952@qq.com
 * DateTime: 2024/8/15 下午5:03
 * SystemName: ym-admin
 *
 */

/**
 * FileName: SystemSettingBasicForm.php
 * Author: 790213952@qq.com
 * DateTime: 2024/8/7 下午12:34
 * SystemName: Ymtc
 *
 */


/**
 * FileName: SiteConfig.php
 * Author: Xiao Yao <790213952@qq.com>
 * DateTime: 2022-09-15 下午 02:23
 * Summary:
 */


namespace YmPhp\Admin\Http\Forms;


use YmPhp\Admin\Models\Setting as SystemSettingModel;
use YmPhp\Admin\Widgets\Alert;
use YmPhp\Admin\Widgets\Form;
use Illuminate\Http\Request;

class WechatConfigForm extends Form
{
    /**
     * The form title.
     *
     * @var string
     */
    public $title = '基本设置';

    /**
     * Handle the form request.
     *
     * @param Request $request
     *
     * @return \YmPhp\Admin\Http\JsonResponse
     */
    public function handle(array $input)
    {
        (new SystemSettingModel())->saveConfig($input, 'system_wechat');
        return $this->response()->success('保存成功')->refresh();
    }

    /**
     * Build a form here.
     */
    public function form()
    {
            $this->html("<h3 style='font-weight: bold'>".__('setting.basic.basic_settings'). "</h3>")->width(10,1);

            $this->text('appid', __('wechat.appid'))->width(4);
            $this->text('app_secert',  __('wechat.app_secert'))->width(4);
            $this->divider();
            $this->html("<h3 style='font-weight: bold'>".__('wechat.wechat_service_setting'). "</h3><span style='font-size: 13px;color: #7b7b7b'>" .__('wechat.wechat_service_info')."</span>")->width(10,1);
            $this->display('url','服务器URL：')->default(env('APP_URL').'/api/wechat/service')->width(4);
            $this->text('wechat_token',  __('wechat.wechat_token'))->width(4)->minLength(3)->maxLength(32);
            $this->divider();
            $this->html("<h3 style='font-weight: bold'>".__('wechat.wechat_open_setting'). "</h3><span style='font-size: 13px;color: #7b7b7b'>" .__('wechat.wechat_open_info')."</span>")->width(10,1);
            $this->text('open_appid', __('wechat.open_appid'))->width(4);
            $this->text('open_app_secert',  __('wechat.open_app_secert'))->width(4);
            $this->divider();
            $this->html("<h3 style='font-weight: bold'>".__('wechat.wechat_other_setting'). "</h3>")->width(10,1);

            $this->switch('pc_subscribe',  __('wechat.pc_subscribe'))->width(4);
            $this->switch('is_mobile',  __('wechat.is_mobile'))->width(4);
            $this->image('pc_login_bg',  __('wechat.pc_login_bg'))->move('upload/channel/wechat/')->autoUpload()->uniqueName()->saveFullUrl()->width(4);
            $this->image('pc_login_logo',  __('wechat.pc_login_logo'))->move('upload/channel/wechat/')->autoUpload()->uniqueName()->saveFullUrl()->width(4);

    }

    /**
     * The data of the form.
     *
     * @return array $data
     */
    public function data()
    {
        $datas = SystemSettingModel::pluck('value', 'key');
        return $datas['system_wechat'];
    }


}



